package com.yh.controller;

import com.sun.media.sound.SoftTuning;
import com.yh.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: als
 * @Date: 2024/5/20 - 05 - 20 - 15:07
 * @Description: com.yh.controller
 * @version: 1.0
 */
//交给spring容器
@Controller
public class UserController {
    //get请求
   @RequestMapping(value = "/user/{id}",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
   @ResponseBody
    public String select(@PathVariable(value = "id",required = false) int id){
       System.out.println("查询数据"+id);
      return "查询id为"+id+"的user的数据";
    }

    //post请求
    @RequestMapping(value = "/user",method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"})//,produces = {"application/json;charset=UTF-8"}
    @ResponseBody
    public User insert(@RequestBody User u){
        System.out.println("添加数据"+u);
        //返回join数据
        return u;
    }

    //put请求
    @RequestMapping(value = "/user",method = RequestMethod.PUT,produces = {"application/json;charset=UTF-8"})//,produces = {"application/json;charset=UTF-8"}
    @ResponseBody
    public User update(@RequestBody User u){
        System.out.println("put修改数据"+u);
        //返回join数据
        return u;
    }

    //delete请求用于删除
    @RequestMapping(value = "/user/{id}",method = RequestMethod.DELETE,produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String delete(@PathVariable(value = "id",required = false) int id){
        System.out.println("delete删除数据"+id);
        return "删除id为"+id+"的user数据";
    }

    @RequestMapping(value = "/{a}/user/list/{b}/{c}",method = RequestMethod.GET)
    @ResponseBody
    public String abc(@PathVariable(value = "a",required = false) int a,@PathVariable(value = "b",required = false) int b,@PathVariable(value = "c",required = false) int c){
        System.out.println(a+","+b+","+c);
        return ""+a+b+c;
    }
    @RequestMapping(value = "/{a}",method = RequestMethod.GET)
    @ResponseBody
    public String abc(@PathVariable(value = "a",required = false) int a) throws InterruptedException {
        System.out.println(a+"111111111");

        Thread.sleep(4000);
        System.out.println(a+"22222222");
        return ""+a;
    }

}
